const db = require('../config/database');

class UserService {
  async create({ username, password }) {
    const sql = `INSERT INTO users(username,password) VALUES(?,?)`;
    const result = await db.execute(sql, [username, password]);
    return result[0];
  }
  async login({ username, password }) {
    const sql = `select *  from users where username=? and password=?`;
    const result = await db.execute(sql, [username, password]);
    return result[0];
  }

  async findUserByName(name) {
    const sql = `select * from users where username = ?`;
    const result = await db.execute(sql, [name]);
    return result[0];
  }
}

module.exports = new UserService();
